

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>系统字典管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../statics/layui/css/layui.css">
    <link rel="stylesheet" href="../../../statics/layui/font/font.css" media="all" />

</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-header">字典添加</div>
        <div class="layui-card-body" style="padding: 15px;">
            <form class="layui-form" lay-filter="form">
                <input type="hidden" name="id" id="id"/>
                <div class="layui-form-item">
                    <label class="layui-form-label">所属分组:</label>
                    <div class="layui-input-block" id="groupList">
                        <select name="groupId" id="groupId" lay-verify="required">
                            <option value="">直接选择或搜索</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">字典名称:</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" id="name" lay-verify="required"  placeholder="请输入字典名称" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">字典值:</label>
                    <div class="layui-input-block">
                        <input type="text" name="value" id="value" lay-verify="required" placeholder="请输入字典值" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">排序号:</label>
                    <div class="layui-input-block">
                        <input type="text" name="sort" id="sort" lay-verify="number" placeholder="请输入排序号" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">可用状态:</label>
                    <div class="layui-input-block" id="statusList">
                        <select name="status" id="status" lay-verify="required">
                            <option value="1">正常</option>
                            <option value="0">不可用</option>
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">备注：</label>
                    <div class="layui-input-block">
                        <textarea rows="" cols="" class="layui-textarea" name="remark" id="remark"></textarea>
                    </div>
                </div>



                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <div class="layui-footer">
                            <button type="button"  lay-submit lay-filter="saveData"  class="layui-btn">保存数据</button>
                            <button type="button" onclick="ysb.closeWind();"  class="layui-btn layui-btn-primary" >关闭窗口</button>
                        </div>
                    </div>
                </div>

            </form>
        </div>
    </div>
</div>
<script type="text/javascript" src="../../../statics/layui/layui.js"></script>
<script type="text/javascript" src="../../../statics/js/sys/editDict.js"  charset="utf-8"></script>
<script>
    layui.use(['form','layer'], function(){
        var layer = layui.layer;
        var form = layui.form;
        var id = configureCom.GetQueryString('id');
        //如果是有ID进来，那就认为为修改
        if(id){//修改
            //详情接口
            var dictUrl = '/sys/dict/info/';
            //获取详情参数
            configureCom.getAjax(dictUrl,{id:id}).then(function(res){
                var data = res.dict;
                form.val('form',data);
                //如果有select选择id，则调用公共select方法构建
                if(data.groupId){           //字典类型  optionId   selectId
                    configureCom.selectDataFun(type,data.groupId,'#groupId');
                }
                form.render();
            })
        }else{//添加
            configureCom.selectDataFun(type,'','#groupId');
        }
        form.render();
        /**
         * 提交监听
         */
        form.on('submit(saveData)', function(data){
            var pathUrl="";
            //判断添加or修改
            if(data.field.id){
                pathUrl="/sys/dict/save";
            }else{
                pathUrl="/sys/dict/update";
            }
            configureCom.postDataAjax(pathUrl,data.field).then(function(res){
                if(res.code=="0"||res.msg=="success"){
                    layer.msg("保存成功");
                    configureCom.closeWind();
                }else{
                    layer.msg(res.msg);
                }
            });
        });
    });
</script>
</body>
</html>
